package com.soap.desensitize.posterity.string;

import com.soap.desensitize.encry.IDesensitization;
import com.soap.desensitize.exception.strategy.DecodeException;
import com.soap.desensitize.exception.strategy.EncodeException;
import com.soap.desensitize.posterity.AbstractPosterity;
import com.soap.desensitize.strategy.irreversible.IdCardStrategy;

/**
 * @desc	身份证加密
 * @author 	gzy
 * @time	2022-04-21
 */
public class IdCardDesensitization extends AbstractPosterity<String> {
    /**
     * @desc 默认使用身份证号替换加密
     */
    private IdCardDesensitization(){
        super(IdCardStrategy.getInstance());
    }

    private static IdCardDesensitization instance = null;
    /**
     * @desc 获得实例
     * @return
     */
    public static synchronized AbstractPosterity getInstance(){
        if(instance == null){
            instance = new IdCardDesensitization();
        }
        return instance;
    }

    /**
     * @desc 有参构造器
     * @param encry
     */
    public IdCardDesensitization(IDesensitization encry) {
        super(encry);
    }

    @Override
    public String encode(String data) throws EncodeException {
        return (String)encry.encode(data);
    }

    @Override
    public String decode(String data) throws DecodeException {
        return (String)encry.decode(data);
    }
}
